<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
require_once( APPPATH . "libraries/alipay/lib/alipay_submit.class.php");
require_once( APPPATH . "libraries/alipay/lib/alipay_notify.class.php");
//支付宝支付类
class Alipay{
    function __construct() {
        
    }
    /**
     * 支付宝充值请求接口
     * @param type $alipay_config 支付宝配置信息
     * @param type $args 请求参数
     */
    public static function recharge($alipay_config,$args){
        //产品类型，无需修改
        $service = "create_direct_pay_by_user";
        //支付类型 ，无需修改
        $payment_type = "1";
        //服务器异步通知页面路径
        $notify_url = $args['notify_url'];
        //面跳转同步通知页面路径
        $return_url = $args['return_url'];
        //商户订单编号，能唯一标识订单的编号
        $out_trade_no = $args['number'];
        //商品名称
        $subject = $args['name'];
        //商品所需金额
        $total_fee = $args['total'];
        //订单描述,可为空值
        $body = $args['content'];
        // 防钓鱼时间戳  若要使用请调用类文件submit中的query_timestamp函数
        $anti_phishing_key = "";
        // 客户端的IP地址 非局域网的外网IP地址，如：221.0.0.1
        $exter_invoke_ip = "";
        
        //构造要请求的参数数组，无需改动
        $parameter = array(
            "service"       => $service,
            "partner"       => $alipay_config['partner'],
            "seller_id"  => $alipay_config['seller_id'],
            "payment_type"	=> $payment_type,
            "notify_url"	=> $notify_url,
            "return_url"	=> $return_url,
            "anti_phishing_key"=>$anti_phishing_key,
            "exter_invoke_ip"=>$exter_invoke_ip,
            "out_trade_no"	=> $out_trade_no,
            "subject"	=> $subject,
            "total_fee"	=> $total_fee,
            "body"	=> $body,
            "_input_charset"	=> trim(strtolower($alipay_config['input_charset']))
        );

        //建立请求
        $alipaySubmit = new AlipaySubmit($alipay_config);
        $html_text = $alipaySubmit->buildRequestForm($parameter,"post", "确认");
        echo $html_text;
    }
    
}

